home *** CD-ROM | disk | FTP | other *** search
- Path: news.eunet.fi!newsmaster
- From: mtg@neste.com (Michael Glasgow)
- Newsgroups: comp.lang.c
- Subject: How to make this get_time function work ?
- Date: 5 Mar 1996 14:34:05 GMT
- Organization: Neste Network Services, Finland
- Distribution: world
- Message-ID: <4hhjct$3og@idefix.eunet.fi>
- Reply-To: mtg@neste.com
- NNTP-Posting-Host: manager.kni.neste.com
-
- #include <stdio.h>
- #include <ctype.h>
- #include <time.h>
- #include <math.h>
- #include <string.h>
- #define STRING_LENGTH 256
-
- int get_time() {
- time_t t=time(NULL);
- struct tm *tp=localtime(&t);
- char time_str[STRING_LENGTH]={0}, str[STRING_LENGTH]={0};
- strftime(time_str, STRING_LENGTH, "%Y%m%d%H%M%S", tp);
- sprintf(str,"%s",time_str);
- /* printf("%s",str); */
- return str;
- }
- main() {
- int tim;
- tim = get_time();
- printf("%s\n", tim);
- }
-
-
- With gcc I get the following error messages:
- ../test.c: In function `get_time':
- ../test.c:15: warning: return makes integer from pointer without a cast
- ../test.c:15: warning: function returns address of local variable
-
- and when I try to return str with atoi conversion --> return atoi(str);
- I can't get anything readable out, any ideas, thanks !
-
- --
-